//
//  ReadPageCollectionViewCell.m
//  LuckyRadio
//
//  Created by JiaRui on 15/11/16.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "ReadPageCollectionViewCell.h"
#define ww self.bounds.size.width
#define hh self.bounds.size.height
@implementation ReadPageCollectionViewCell
- (void)dealloc
{
    [_picture release];
    [_nameLabel release];
    [super dealloc];
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
//        _backView = [[UIView alloc]init];
//        _backView.userInteractionEnabled = YES;
//        _backView.layer.cornerRadius = 10;
//        _backView.layer.masksToBounds = YES;
//        _backView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
//        [self.contentView addSubview:_backView];

        
//        _picture.backgroundColor = [UIColor magentaColor];
        _picture = [[UIImageView alloc]init];
        _picture.userInteractionEnabled = YES;
        _picture.layer.cornerRadius = 10;
        _picture.layer.masksToBounds = YES;

        [self.contentView addSubview:_picture];
        [_picture release];
        
        
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.backgroundColor = [UIColor whiteColor];
        _nameLabel.userInteractionEnabled = YES;
        _nameLabel.layer.cornerRadius = 10;
        _nameLabel.layer.masksToBounds = YES;
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
//    self.backView.frame = self.contentView.frame;
    self.picture.frame = CGRectMake(ww / 9, hh / 11, ww - (ww / 9) * 2, (hh - 40 - (hh / 11 * 2)));
    self.nameLabel.frame = CGRectMake(self.picture.frame.origin.x, self.picture.frame.origin.y + self.picture.frame.size.height + 10, self.picture.frame.size.width , 40);
//    self.nameLabel.frame = CGRectMake(self.picture.frame.origin.x, self.picture.frame.origin.y + self.picture.frame.size.height, self.picture.frame.size.width , 40);
}
-(void)setModel:(ReadPageModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.picture sd_setImageWithURL:[NSURL URLWithString:model.coverimg] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@%@", model.name, model.enname];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
}
@end
